#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <cstring>


int main(int argc, char *argv[])
{
        int sock = socket(AF_INET, SOCK_STREAM, 0);

        struct sockaddr_in saClient;
        struct hostent * my_hostent;
        my_hostent = gethostbyname("localhost");
        int i = 0;

        saClient.sin_family = AF_INET; 
        saClient.sin_addr = *( struct in_addr*)( my_hostent-> h_addr_list[0]);
        saClient.sin_port = htons(10000);
   
        if (connect(sock, (sockaddr*) &saClient, sizeof(saClient)) != 0)
        {
                printf("couldn't connect socket\n");
                return 1;
        }

        char message[] = "Hello server";
		char * message2;
        size_t size = sizeof (saClient);
        int nbytes = sendto (sock, message, strlen(message) + 1, 0,
                   (struct sockaddr *) & saClient, size); 

	int n =0;	
	if((n = recvfrom(sock, message2, 512, 0, (struct sockaddr *) NULL, NULL)) < 0)
	{
		printf("couldn't get message\n");		
		return 1;
    }
    
    printf("%s\n", message2);  
    
      
    return 0;
}

